import Taro, {  Config } from '@tarojs/taro'
import React, { Component } from 'react'
import { View } from '@tarojs/components'

type PageProps = {}
type PageState = {}

class Photograph extends Component<PageProps, PageState> {
  state = {}
  config: Config = {}
  photograph() {
    // 允许从相机和相册扫码
    Taro.scanCode({
      success: (res) => {
        Taro.showToast({
          title: res.result,
          icon: 'none'
        })
        console.log(res)
      },
      fail(_) {
        Taro.showToast({
          title: '扫码失败',
          icon: 'none'
        })
      }
    })
  }

  render() {
    return <View onClick={this.photograph.bind(this)}>{this.props.children}</View>
  }
}

export default Photograph
